<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>1_类的基本知识</title>
</head>
<body>
  <script type="text/javascript">
    // 创建一个类
    class Person {
      // 构造器函数  构造器this指向类的实例对象
      constructor (name, age) {
        this.age = age
        this.name = name
      }

      // 类中可以直接写赋值语句,如下代码的含义: 给Person的实例对象添加一个属性
      a = 1
      wheel = 4
      run = () => {
        
      }

      // 一般方法 speak放在类的原型对象上,供实例使用
      speak () {
        console.log(`我叫${this.name},年龄是${this.age}`)
      }
    }

    class student extends Person {
      constructor (name, age, grade) {
        super(name, age)
        this.grade = grade 
        this.school = `尚硅谷`
      }
      // 重写从父类继承过来的方法
      speak () {
        console.log(`我叫${this.name},我年龄是${this.age},读的是${this.grade}年纪`)
      }
    }

    const p1 = new Person('tom', 18,'高一');
    const p2 = new student('wares', 23, '大四')
    p1.speak()
    p2.speak()
    // console.log(p1)
    console.log(p2)
  </script>
</body>
</html>